package com.pan.test.socket.example01;

import com.pan.utils.PrintTime;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;


/**
 * client
 * 1.发送信息
 * 2.接收信息
 * 3.用字节流收发
 */
public class MyClient {
    public static void main(String[] args) throws Exception {

        InetAddress localHost = InetAddress.getLocalHost();
        Socket socket = new Socket(localHost, 11451);
        String msg = "hello server 你好(采用字节流发送)";
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write(msg.getBytes());
        socket.shutdownOutput();



        InputStream inputStream = socket.getInputStream();
        byte[] buf = new byte[1024];
        int len;
        while ((len = inputStream.read(buf))!=-1){
            System.out.print(new String(buf,0,len));
        }



        inputStream.close();

        outputStream.close();
        socket.close();


    }
}
